#
# "@(#) $Id: ShuttleWidget.py,v 1.1.1.1 2006-07-27 03:16:08 gioshe Exp $"
#
# This work is released under the GNU GPL, version 2 or later.
#
from qt import *
from PixmapPushButton import *
from MultiPushButton import *
from Player import *
from Utils.Paths import *

class ShuttleWidget(QWidget):
	def __init__(self,container = None):
		QWidget.__init__(self,container)
		self.setFixedHeight(45)
		self.buildControls()
		QObject.connect(Player.singleton(),PYSIGNAL('playback_status'),self.gotStatus)
		self.lastMode = "Blah"
		print Settings.settings()
		#.get('ColorR'),Settings.settings().get('ColorG'),Settings.settings().get('ColorB')
		backColor=QColor(Settings.settings().get('ColorR'),Settings.settings().get('ColorG'),Settings.settings().get('ColorB'))
		self.setPaletteBackgroundColor(backColor)
		self.setFixedWidth(120)

	
	def gotStatus(self,status):
		if status:
			mode = status['Status']
			if True: #mode!=self.lastMode:
				if mode=='End':
					self.playPauseStopButton.setState('play')
				elif status['isPlaying']:
					self.playPauseStopButton.setState('pause')
				else:
					self.playPauseStopButton.setState('play')
				self.lastMode = mode
		
	def buildControls(self):
		controls = QHBoxLayout(self)
		controls.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		#controls.setSpacing(3)

		#
		# prev track button button
		#
		print art("buttonrewind.png"),"<<<<<<<"
		self.prevButton = PixmapPushButton(QIconSet(QPixmap(art("buttonrewind.png"))),"",self)
		controls.addWidget(self.prevButton)
		QObject.connect(self.prevButton,SIGNAL("clicked()"),self.slotPrevTrack)

		#
		# play/pause/stop button
		#
		iconplay = QIconSet(QPixmap(art("buttonplay.png")))
		iconpause = QIconSet(QPixmap(art("buttonpause.png")))
		iconstop = QIconSet(QPixmap(art("buttonstop.png")))
		self.playPauseStopButton = PixmapMultiPushButton("",self)
		self.playPauseStopButton.addState('play',iconplay,PYSIGNAL("play"))
		self.playPauseStopButton.addState('pause',iconpause,PYSIGNAL("pause"))
		#self.playPauseStopButton.addState('stop',iconstop,PYSIGNAL("stop"))
		controls.addWidget(self.playPauseStopButton)
		QObject.connect(self.playPauseStopButton,PYSIGNAL("play"),self.slotPlay)
		QObject.connect(self.playPauseStopButton,PYSIGNAL("pause"),self.slotPause)
		#QObject.connect(self.playPauseStopButton,PYSIGNAL("stop"),self.slotStop)
		self.playPauseStopButton.setState('play')
		#
		# stop play button
		#
		self.stopButton = PixmapPushButton(QIconSet(QPixmap(art("buttonstop.png"))),"",self)
		controls.addWidget(self.stopButton)
		QObject.connect(self.stopButton,SIGNAL("clicked()"),self.slotStop)
		QObject.connect(self.stopButton,PYSIGNAL("stop"),self.slotStop)

		#
		# next track button
		#
		self.nextButton = PixmapPushButton(QIconSet(QPixmap(art("buttonfastforward.png"))),"",self)
		controls.addWidget(self.nextButton)
		QObject.connect(self.nextButton,SIGNAL("clicked()"),self.slotNextTrack)

		controls.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		
	def slotPrevTrack(self):
		self.emit(PYSIGNAL("prevTrack"),(self,None))
	
	def slotNextTrack(self):
		self.emit(PYSIGNAL("nextTrack"),(self,None))
		
	def slotPlay(self):
		#print "Hit Play"
		self.emit(PYSIGNAL("play"),(self,None))
	
	def slotPause(self):
		#print "Hit Pause"
		self.emit(PYSIGNAL("pause"),(self,None))
	
	def slotStop(self):
		#print "Hit Stop"
		self.emit(PYSIGNAL("stop"),(self,None))

	def setState(self,state):
		self.playPauseStopButton.setState(state)
